﻿using Microsoft.Practices.Unity.Configuration;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;

namespace JZ.JiangSu.Common.DependencyInjection
{
    public static class IocContainerProvider
    {
        private static IUnityContainer _iocContainer;
        public static IUnityContainer IocContainer { get { return _iocContainer; } }

        static IocContainerProvider()
        {
            _iocContainer= new UnityContainer();
            //UnityConfigurationSection config = (UnityConfigurationSection)ConfigurationManager.GetSection(UnityConfigurationSection.SectionName);
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = "Unity.config";
            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            ConfigurationSection section = configuration.GetSection("unity");
            _iocContainer.LoadConfiguration((UnityConfigurationSection)section);

        }
    }
}
